package com.linkstec.mot.queue;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.linkstec.mot.util.ConfigUtil;
import com.linkstec.mot.util.ExceptionTracker;

/**
 * 数据处理缓存队列
 * 
 * @author PENGYAO
 * 
 */
public class DataQueue {

	private static Logger logger = LoggerFactory.getLogger(DataQueue.class);

	private static BlockingQueue<Object> queue;

	/**
	 * 
	 * @return
	 */
	public static Object poll() {
		return queue.poll();
	}

	/**
	 * 
	 * @param tempItem
	 */
	public static void put(Object tempItem) {
		try {
			queue.put(tempItem);
		} catch (InterruptedException e) {
			logger.error(ExceptionTracker.trace(e));
		}
	}

	/**
	 * 队列默认3000长度
	 */
	private static synchronized void init() {
		if (queue == null) {
//			int queueSize = 2000;
			int queueSize =Integer.parseInt(ConfigUtil.getProperty("queueSize"));
			queue = new LinkedBlockingDeque<Object>(queueSize);
			logger.info("DataQueue size：" + queueSize);
		}
	}

	/**
	 * 
	 */
	static {
		init();
	}
}
